package com.ruozedata.bigdata.lesson03

/**
 * object   class
 *
 */
object ApplyApp {

    def main(args: Array[String]): Unit = {

        //ApplyTest.static()

        //for (i <- 1 to 10) {
        //    println()
        //}

        val a = new ApplyTest
        println(a)
        a.test()

        println("----------------------")

        // *****
        val b = ApplyTest() // 没有使用new xxx() => object apply  经常使用   不用new就能实力话 fixme
        println(b)
        val c = new ApplyTest()  // 对象（）=> class apply
        println(c)
    }
}

/**
 * object 定义的方法 调用不用new
 */
object Timer {
    var cnt = 0

    def currentCnt:Int = {
        cnt += 1
        cnt
    }
}

class ApplyTest {
    println("ApplyTest class enter ...")

    def test(): Unit = {
        println("ApplyTest class test method work....")
    }

    def apply(): Unit = {
        println("ApplyTest Class apply work....")
    }
    println("ApplyTest class Out ....")
}

/**
 * object xxx
 * class xxx
 * 伴生类  和  伴生对象
 * 互为伴生
 */
object ApplyTest {
    println("ApplyTest object enter ...")

    def static(): Unit = {
        println("static..........")
    }

    var cnt = 0
    def inc():Unit = cnt += 1

    def apply(): Unit = {
        println("ApplyTest object apply method work...")
        new ApplyTest()
    }

    println("out ... ")
}
